package com.ruoyi.project.learn.xxcl.controller;

import java.util.List;

import com.ruoyi.project.system.cms.domain.CommonCms;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.learn.xxcl.domain.DjStudyMaterial;
import com.ruoyi.project.learn.xxcl.service.IDjStudyMaterialService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 学习材料Controller
 * 
 * @author ruoyi
 * @date 2025-09-17
 */
@Controller
@RequestMapping("/learn/xxcl")
public class DjStudyMaterialController extends BaseController
{
    private String prefix = "learn/xxcl";

    @Autowired
    private IDjStudyMaterialService djStudyMaterialService;

    @RequiresPermissions("learn:xxcl:view")
    @GetMapping()
    public String xxcl()
    {
        return prefix + "/xxcl";
    }

    /**
     * 查询学习材料列表
     */
    @RequiresPermissions("learn:xxcl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjStudyMaterial djStudyMaterial)
    {
        startPage();
        List<DjStudyMaterial> list = djStudyMaterialService.selectDjStudyMaterialList(djStudyMaterial);
        return getDataTable(list);
    }

    /**
     * 导出学习材料列表
     */
    @RequiresPermissions("learn:xxcl:export")
    @Log(title = "学习材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjStudyMaterial djStudyMaterial)
    {
        List<DjStudyMaterial> list = djStudyMaterialService.selectDjStudyMaterialList(djStudyMaterial);
        ExcelUtil<DjStudyMaterial> util = new ExcelUtil<DjStudyMaterial>(DjStudyMaterial.class);
        return util.exportExcel(list, "学习材料数据");
    }

    /**
     * 新增学习材料
     */
    @RequiresPermissions("learn:xxcl:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学习材料
     */
    @RequiresPermissions("learn:xxcl:add")
    @Log(title = "学习材料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjStudyMaterial djStudyMaterial)
    {
        return toAjax(djStudyMaterialService.insertDjStudyMaterial(djStudyMaterial));
    }

    /**
     * 修改学习材料
     */
    @RequiresPermissions("learn:xxcl:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DjStudyMaterial djStudyMaterial = djStudyMaterialService.selectDjStudyMaterialById(id);
        mmap.put("djStudyMaterial", djStudyMaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存学习材料
     */
    @RequiresPermissions("learn:xxcl:edit")
    @Log(title = "学习材料", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjStudyMaterial djStudyMaterial)
    {
        return toAjax(djStudyMaterialService.updateDjStudyMaterial(djStudyMaterial));
    }

    /**
     * 删除学习材料
     */
    @RequiresPermissions("learn:xxcl:remove")
    @Log(title = "学习材料", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djStudyMaterialService.deleteDjStudyMaterialByIds(ids));
    }

    /**
     * 查看学习材料内容
     */
    @RequiresPermissions("learn:xxcl:view")
    @GetMapping("/view/{id}")
    @Log(title = "学习材料", businessType = BusinessType.OTHER)
    public String view(@PathVariable("id") Long id, ModelMap mmap)
    {
        DjStudyMaterial commonCms = djStudyMaterialService.selectDjStudyMaterialById(id);
        mmap.put("commonCms", commonCms);
        return prefix + "/view";
    }
}
